package cn.zyq.ykb.controller.h5.user;

import cn.zyq.ykb.beans.task.bo.UserUpgradeBo;
import cn.zyq.ykb.beans.user.User;
import cn.zyq.ykb.beans.user.UserCash;
import cn.zyq.ykb.beans.user.bo.BindAlipayBo;
import cn.zyq.ykb.beans.user.bo.FillInviteCodeBo;
import cn.zyq.ykb.beans.user.bo.UserUptRatioBo;
import cn.zyq.ykb.beans.user.bo.WxLoginBo;
import cn.zyq.ykb.beans.user.dto.UserLoginDto;
import cn.zyq.ykb.service.user.UserService;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;
import cn.zyq.ykb.system.config.sms.SmsConfig;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.system.utils.Sample;
import com.alipay.api.kms.aliyun.http.MethodType;
import com.aliyun.tea.TeaModel;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author pengdoudou
 * @Date 2023/4/20 14:43
 */
@Api(tags = "用户表")
@RestController(value = "H5UserController")
@RequestMapping(value = "/api/user")
@Slf4j
public class UserController extends BaseController {

    @Autowired
    private UserService userService;

    /**
     * 获取微信登录
     *
     * @param bo    请求内容
     * @param request 请求对象
     * @return 登录结果
     */
    @PostMapping("/wxLogin")
    public Object wxLogin(@RequestBody WxLoginBo bo, HttpServletRequest request) {
        return this.userService.wxLogin(bo, request);
    }

//    /**
//     * 获取用户手机号
//     *
//     * @param code
//     * @return
//     */
//    @GetMapping("getPhone/{code}")
//    public Object getPhone(@PathVariable("code") String code) {
//        return this.userService.getPhone(code, this.getLoginUser());
//    }

    /**
     * 更新用户头像昵称和性别等信息
     *
     * @param user   用户信息
     * @return 支付订单ID
     */
    @PostMapping("updateInfo")
    public Object updateInfo(@RequestBody User user) {
        return this.userService.updateInfo(this.getLoginUser(), user);
    }

    /**
     * 获取用户信息
     *
     * @return 支付订单ID
     */
    @GetMapping("userInfo")
    public Object userInfo() {
        return this.getLoginUser();
    }

    /**
     * 手机号注册
     *
     * @param dto 请求内容
     * @return
     */
    @ApiOperation(value = "手机号注册")
    @PostMapping("/bindPhone")
    public Object bindPhone(@RequestBody UserLoginDto dto) {
        return this.userService.bindPhone(dto);
    }

    /**
     * 发送短信验证码
     *
     * @param phone 手机号
     * @return
     */
    @ApiOperation(value = "发送短信验证码")
    @GetMapping("/smsCode/{phone}")
    public Object smsCode(@PathVariable("phone") String phone){
        return this.userService.smsCode(phone);
    }

    /**
     * 验证码登录
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "验证码登录")
    @PostMapping("/smsLogin")
    public Object smsLogin(@RequestBody UserLoginDto dto) {
        return this.userService.smsLogin(dto);
    }

    /**
     * 个人信息
     *
     * @param
     * @return
     */
    @ApiOperation(value = "个人信息")
    @GetMapping("/person/{phone}")
    public Object person(@PathVariable("phone") String phone) {
        return this.userService.person(phone,this.request);
    }

    /**
     * 修改头像
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改头像")
    @PostMapping("/updateHead")
    public Object updateHead(@RequestBody User user) {
        return this.userService.updateHead(user,this.getLoginUser());
    }

    /**
     * 修改昵称
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改昵称")
    @PostMapping("/uptName")
    public Object uptName(@RequestBody User user) {
        return this.userService.uptName(user,this.getLoginUser());
    }

    /**
     * 修改手机号
     *
     * @param dto 请求内容
     * @return
     */
    @ApiOperation(value = "修改手机号")
    @PostMapping("/updatePhone")
    public Object updatePhone(@RequestBody UserLoginDto dto) {
        return this.userService.updatePhone(dto, this.getLoginUser());
    }

    /**
     * 绑定支付宝账号
     * @param bo
     * @return
     */
    @ApiOperation(value = "绑定支付宝账号")
    @PostMapping("/bindAlipay")
    public Object bindAlipay(@RequestBody BindAlipayBo bo) {
        return this.userService.bindAlipay(bo,this.getLoginUser());
    }

    /**
     * 修改支付宝账号
     * @param bo
     * @return
     */
    @ApiOperation(value = "修改支付宝账号")
    @PostMapping("/uptAlipay")
    public Object uptAlipay(@RequestBody BindAlipayBo bo) {
        return this.userService.uptAlipay(bo,this.getLoginUser());
    }

    /**
     * 填写邀请码
     *
     * @param bo 请求内容
     * @return
     */
    @ApiOperation(value = "填写邀请码")
    @PostMapping("/fillInviteCode")
    public Object fillInviteCode(@RequestBody FillInviteCodeBo bo) {
        return this.userService.fillInviteCode( bo);
    }

    /**
     * 我的导师
     * @return
     */
    @ApiOperation(value = "我的导师")
    @GetMapping("/getWxCode")
    public Object getWxCode() {
        return this.userService.getWxCode( this.getLoginUser());
    }

    /**
     * 我的团队
     * @return
     */
    @ApiOperation(value = "我的团队")
    @PostMapping("/getMyTeam")
    public Object getMyTeam(@RequestBody PageParam pageParam) {
        return this.userService.getMyTeam(pageParam,this.getLoginUser());
    }

    /**
     * 我的团队统计
     * @return
     */
    @ApiOperation(value = "我的团队统计")
    @GetMapping("/getMyTeamTotal")
    public Object getMyTeamTotal() {
        return this.userService.getMyTeamTotal(this.getLoginUser());
    }


    /**
     * 用户提现申请
     */
    @ApiOperation(value = "用户提现申请")
    @PostMapping("/withdraw")
    public Object withdraw(@RequestBody UserCash param) {
        log.info("用户申请提现开始{}",param);
        User loginUser = this.getLoginUser();
        synchronized (loginUser.getServiceID()+ "withdraw".intern()){
            return this.userService.withdraw(param, loginUser,this.request);
        }
    }

    /**
     * 填写客服微信
     * @return
     */
    @ApiOperation(value = "填写客服微信")
    @GetMapping("/addCustomer/{customer}")
    public Object addCustomer(@PathVariable("customer") String customer) {
        return this.userService.addCustomer(customer,this.getLoginUser());
    }

    /**
     * 团队长收益
     * @return
     */
    @ApiOperation(value = "团队长收益")
    @PostMapping("/income")
    public Object income(@RequestBody PageParam pageParam) {
        return this.userService.income(pageParam,this.getLoginUser());
    }

    /**
     * 添加团队长
     * @return
     */
    @ApiOperation(value = "添加团队长")
    @PostMapping("/addIncome")
    public Object addIncome(@RequestBody PageParam pageParam) {
        return this.userService.addIncome(pageParam,this.getLoginUser());
    }

    /**
     * 调整比例
     * @return
     */
    @ApiOperation(value = "调整比例")
    @PostMapping("/uptRatio")
    public Object uptRatio(@RequestBody UserUptRatioBo bo) {
        return this.userService.uptRatio(bo,this.getLoginUser());
    }

    /**
     * 获取团队长名额
     * @return
     */
    @ApiOperation(value = "获取团队长名额")
    @PostMapping("/getNumber")
    public Object getNumber() {
        return this.userService.getNumber(this.getLoginUser());
    }

    /**
     * 升级
     */
    @ApiOperation(value = "升级")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PostMapping("/upgradation")
    public Object upgradation(@RequestBody UserUpgradeBo bo) {
        return this.userService.upgradation(bo,this.getLoginUser());
    }

    /**
     * 获取比例
     * @return
     */
    @ApiOperation(value = "获取比例")
    @GetMapping("/getRatio")
    public Object getRatio() {
        return this.userService.getRatio(this.getLoginUser());
    }

    /**
     * 查询我的团队的团队长数据
     * @return
     */
    @ApiOperation(value = "查询我的团队的团队长数据")
    @GetMapping("/getMyTuz")
    public Object getMyTuz() {
        return this.userService.getMyTuz(this.getLoginUser());
    }

    /**
     * 累计任务收益
     * @return
     */
    @ApiOperation(value = "累计任务收益")
    @GetMapping("/getMoney")
    public Object getMoney() {
        return this.userService.getMoney(this.getLoginUser());
    }

    /**
     * 累计任务收益
     * @return
     */
    @ApiOperation(value = "获取游戏赚收益")
    @GetMapping("/getYXMoney")
    public Object getYXMoney() {
        BigDecimal yxMoney = this.userService.getYXMoney(this.getLoginUser());
        if (yxMoney != null){
            return yxMoney;
        }else {
            return new BigDecimal(0);
        }

    }

    /**
     * 累计任务收益
     * @return
     */
    @ApiOperation(value = "获取任务赚收益")
    @GetMapping("/getRWMoney")
    public Object getRWMoney() {
        BigDecimal rwMoney = this.userService.getRWMoney(this.getLoginUser());
        if (rwMoney != null){
            return rwMoney;
        }else {
            return new BigDecimal(0);
        }

    }

    /**
     * 累计任务收益
     * @return
     */
    @ApiOperation(value = "获取课程收益")
    @GetMapping("/getKCMoney")
    public Object getKCMoney() {
        BigDecimal kcMoney = this.userService.getKCMoney(this.getLoginUser());
        if (kcMoney != null){
            return kcMoney;
        }else {
            return new BigDecimal(0);
        }
    }
    /**
     * 累计任务收益
     * @return
     */
    @ApiOperation(value = "获取课程余额明细")
    @PostMapping("/getKCDetail")
    public Object getKCDetail(@RequestBody PageParam pageParam) {
        return this.userService.getKCDetail(pageParam,this.getLoginUser());
    }

}

